"use strict";

/**
 * @auther wtfssd
 * Created by wtfssd on 2017/11/27
 */
import * as React from 'react'
import {commonStyles} from "../assets/styles/common";
import Avatar from "./Avatar";
import MyText from "./MyText";
import Colors from "../assets/styles/Colors";
import {NoticeItemProps} from "../interface/index";
import Request from "../utils/Request";

const moment = require("moment");

const {View, TouchableOpacity} = require('react-native');
const {connect} = require('react-redux');

class NoticeItem extends React.Component<NoticeItemProps, any> {

    static defaultProps = {
        onPress: null
    };

    constructor(props: NoticeItemProps, context: any) {
        super(props, context);
    }

    getText = () => `${this.props.item.nickname ? '您的联系人' : ''}${this.props.item.nickname}给您发了一条新消息`;

    getTime = () => {
        return moment(this.props.item.sendTime).format('MM-DD HH:mm')
    };

// backgroundColor: this.props.item.action === 'theme' ? 'transparent' : Colors.Background
    render() {
        return (
            <TouchableOpacity style={[commonStyles.flexRow, commonStyles.relative, {
                padding: 10,
                alignItems: 'center',

            }]} onPress={this.props.onPress}
            >
                <Avatar source={{uri: Request.checkImageUrl(this.props.item.avatar)+''}}/>
                <MyText numberOfLines={2} style={{marginLeft: 5}}>{this.getText()}</MyText>
                <View style={[commonStyles.absolute, {top: 5, right: 5}]}>
                    <MyText fontSize={12} color={Colors.Black}>{this.getTime()}</MyText>
                </View>
            </TouchableOpacity>
        );
    }
}


export default NoticeItem;